<?php

//Fungsi Untuk mengirim Pesan
function trigger($penerima,$pesanKirim){
        $tanggal=Date("d M Y");
        $jam=Date("H:i:s");
        //$kirim=changePlusToSpace($pesanKirim);
        //mysql_query("INSERT INTO outbox VALUES('','$tanggal','$jam','$penerima','$kirim')");
        header("Location:http://localhost:8800/?PhoneNumber=$penerima&Text=$pesanKirim");
    
//echo $pesanKirim;
	}
function selectPelapor($pengirim){
    $user=mysql_query("SELECT id_user FROM  user WHERE id_user = '$pengirim' ");
            if(!$user){
                    return NULL;
            }
            $hasiluser=mysql_fetch_array($user);
        return $hasiluser[0];
    }

function selectSekolah($pengirim){
    $sekolah=mysql_query("SELECT id_sekolah FROM  user WHERE id_user = '$pengirim'");
            if(!$sekolah){
                    return NULL;
            }
            $hasilsekolah=mysql_fetch_array($sekolah);
        return $hasilsekolah[0];
    }
function selectJlmToilet($sekolah_pelapor){
	$jmlToilet=mysql_query("SELECT  jumlah_toilet FROM  sekolah WHERE id_sekolah = '$sekolah_pelapor'");
            if(!$jmlToilet){
                    return NULL;
            }
            $hasilJmlToilet=mysql_fetch_array($jmlToilet);
        return $hasilJmlToilet[0];
    }
function kesalahan ($id_kesalahan){
    $jnsLaporan=mysql_query("SELECT  jenis_laporan FROM kategori_laporan WHERE id_kategori_laporan = '$id_kesalahan'");
            if(!$jnsLaporan){
                    return NULL;
            }
            $hasilJnsLaporan=mysql_fetch_array($jnsLaporan);
        return $hasilJnsLaporan[0];
}

function insert_laporan($pengirim, $no_toilet,  $id_kesalahan){
    $waktu=date("Y-m-d H:i:s");
    $kesalahan=kesalahan($id_kesalahan);
    mysql_query("INSERT INTO `laporan` (`waktu_laporan`, `no_toilet`, `id_kategori_laporan`, `isi_laporan`, `id_user`) VALUES ('$waktu','$no_toilet','$id_kesalahan','$kesalahan','$pengirim')");
}

function insert_laporan_masalahBaru($pengirim, $no_toilet,  $id_kesalahan, $kesalahanBaru){
    $waktu=date("Y-d-m H:i:s");
    $kesalahan=strtolower($kesalahanBaru);   
    mysql_query("INSERT INTO `laporan` (`waktu_laporan`, `no_toilet`, `id_kategori_laporan`, `isi_laporan`, `id_user`) VALUES ('$waktu','$no_toilet','$id_kesalahan','$kesalahan','$pengirim')");
}

function  selectNoPengelola($sekolah_pelapor){
    $NoPengelola=mysql_query("SELECT  `Nmr_pengelola_toilet` FROM  `sekolah` WHERE  `id_sekolah` =  '$sekolah_pelapor'");
            if(!$NoPengelola){
                    return NULL;
            }
            $hasilNoPengelola=mysql_fetch_array($NoPengelola);
        return $hasilNoPengelola[0];
}
function selectAdmin($no_pengirim){
    $user=mysql_query("SELECT  `id_user` FROM  `user` WHERE  `id_kategori_user` =  '1'
                        OR  `id_kategori_user` =  '2' AND `id_kategori_user` =  '$no_pengirim'");
            if(!$user){
                    return NULL;
            }
            $hasiluser=mysql_fetch_array($user);
        return $hasiluser[0];
    }
?>